package com.bitejiuyeke.biteadminservice.house.service.strategy;

import com.bitejiuyeke.biteadminservice.house.domain.enums.HouseSortEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 排序策略工厂
 */
@Slf4j
public class SortStrategyFactory{
    public static ISortStrategy getSortStrategy(String sort){
        if(StringUtils.isNotEmpty( sort)){
            if(sort.equalsIgnoreCase(HouseSortEnum.DISTANCE.name())){
                return DistanceSortStrategy.getInstance();
            }else if(sort.equalsIgnoreCase(HouseSortEnum.PRICE_DESC.name())){
                return PriceSortStrategy.getInstance(false);
            }else if(sort.equalsIgnoreCase(HouseSortEnum.PRICE_ASC.name())){
                return PriceSortStrategy.getInstance(true);
            }else {
                log.error("排序规则不存在");
                return DistanceSortStrategy.getInstance();
            }
        }
        return DistanceSortStrategy.getInstance();
    }
}
